How do I?

[ Start > Getting Started > How do I? ] [ Edit this Page | Show Page Versions | Show Formatted ]


__Q. How can I read a file into a string?__

Use __Stdio.read_file()__:

{code}
  // read the contents of foo.txt into variable s. 
  // If the file doesn't exist or could not be read, s will be set to 0 (zero).
  string s = Stdio.read_file("foo.txt"); 
{code}

__Q. How can a I write a string to a file?__

Use __Stdio.write_file()__:

{code}
  // write the contents of variable s into foo.txt (replacing any existing contents).
  // the variable x will be set to the number of bytes written to the file.
  // If the file doesn't exist or could not be could not be written, x will be set to 0 (zero).
  string s =  "some text";
  int x = Stdio.write_file("foo.txt", s);
{code}

Powered by PikeWiki2

 
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University